package com.tenglong.teacher.ui.homepage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cuotibao.zhuoxiao.basics.utils.ToastUtils;
import com.tenglong.teacher.R;
import com.tenglong.teacher.ui.common.activity.BaseActivity;
import com.tenglong.teacher.ui.utils.MyUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class ClassActivity extends BaseActivity {
    RelativeLayout mStuSign;
    RelativeLayout mClassNowInfor;
    RelativeLayout mPushHomework;
    RelativeLayout mClassOut;

    private String classid = null;
    private TextView tvDate;//tv_date
    private TextView tvTime;//tv_time
    private TextView tvTeacher;//tv_teacher
    private TextView tvStuNum;//tv_stu_num
    private TextView tvProject;//tv_project
    private TextView tvPeriod;//tv_period

    private int stuCount = 0;






    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_class_detail);

        tvDate = findViewById(R.id.tv_date);//tv_date
        tvTime = findViewById(R.id.tv_time);//tv_time
        tvTeacher = findViewById(R.id.tv_teacher);//tv_teacher
        tvStuNum = findViewById(R.id.tv_stu_num);//tv_stu_num
        tvProject = findViewById(R.id.tv_project);//tv_project
        tvPeriod = findViewById(R.id.tv_period);//tv_period


        Intent intent = getIntent();
        classid = intent.getStringExtra(MyUtils.CLASSID);
        try {
            final String from = intent.getStringExtra(MyUtils.CLASSDateTimeFrom);
            final String to = intent.getStringExtra(MyUtils.CLASSDateTimeTo);
            if(from == null || to == null){
                tvDate.setText("服务器返回错误");
                tvTime.setText("服务器返回错误");
            }else {
                SimpleDateFormat f = new SimpleDateFormat("yyyy年MM月dd日");
                String timeinfor = f.format(f.parse(from)) + "(" + MyUtils.dateToWeek(from) + ")";
                tvDate.setText(timeinfor);

                SimpleDateFormat f1 = new SimpleDateFormat("HH:mm");
                timeinfor = f1.format(f.parse(from))
                        + "-"
                        + f1.format(f.parse(to));
                tvTime.setText(timeinfor);
            }
        } catch (ParseException ex) {
            ex.printStackTrace();
        }


        tvTeacher.setText(intent.getStringExtra(MyUtils.CLASSPROTEACHER));
        tvStuNum.setText("人数："+intent.getStringExtra(MyUtils.CLASSSTUNUM)+"人");
        tvProject.setText("课节名："+intent.getStringExtra(MyUtils.CLASSCOURSENAME));
        tvPeriod.setText(intent.getStringExtra(MyUtils.CLASSHOUR)+"课时");

        stuCount = Integer.valueOf(intent.getStringExtra(MyUtils.CLASSSTUNUM));


        Log.i(MyUtils.TAG,classid);
        Log.i(MyUtils.TAG,intent.getStringExtra(MyUtils.CLASSNAME));
        //getActionBar().setTitle(intent.getStringExtra("classname"));
        setTitle(intent.getStringExtra(MyUtils.CLASSNAME));

        mStuSign = findViewById(R.id.rl_stusign);
        mClassNowInfor = findViewById(R.id.rl_classnowinfor);
        mPushHomework = findViewById(R.id.rl_pushhomework);
        mClassOut = findViewById(R.id.rl_classout);


        mStuSign.setOnClickListener(this);
        mClassNowInfor.setOnClickListener(this);
        mPushHomework.setOnClickListener(this);
        mClassOut.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        super.onClick(view);

        if(stuCount <= 0){
            ToastUtils.showCenterToast("该班级还没有同学");
            return;
        }
        switch (view.getId()) {
            case R.id.rl_stusign:
                ToastUtils.showCenterToast("功能维护中,敬请期待！");
//                startActivity(new Intent(this,StudentSignActivity.class));
                break;
            case R.id.rl_classnowinfor:
                ToastUtils.showCenterToast("课堂信息");
                break;
            case R.id.rl_pushhomework:
                ToastUtils.showCenterToast("布置作业");
                Intent intent = new Intent(getApplicationContext(),PublishHomeworkActivity.class);
                intent.putExtra(MyUtils.CLASSID,classid);
                startActivity(intent);
                break;
            case R.id.rl_classout:
                ToastUtils.showCenterToast("下课");
                break;
        }

    }

}
